#include "StdAfx.h"
#include "MyComboBox.h"


MyComboBox::MyComboBox(void)
{
}


MyComboBox::~MyComboBox(void)
{
}


HWND MyComboBox::createComboBox(LPCWSTR text,int styles,int x, int y, int cx,int cy, HWND hParent, int id ,
	int nHeight,int fnWeight , BOOL fdwItalic , BOOL fdwUnderline, LPTSTR font, HINSTANCE hInst)
{
	InitCommonControls();

	hInstance = hInst;
	hComboBox = CreateWindowEx (WS_EX_WINDOWEDGE,WC_COMBOBOXEX,text,
		styles,x,y,cx,cy,hParent,(HMENU) id,hInst,NULL); 	

	HFONT hFont = CreateFont(nHeight,0,0,0,fnWeight,fdwItalic,fdwUnderline,0,VIETNAMESE_CHARSET,OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, VARIABLE_PITCH,font);

	SendMessage(hComboBox,WM_SETFONT,(WPARAM)hFont, 0);

	return hComboBox;
}


HWND MyComboBox::getHandle()
{
	return hComboBox;
}


void MyComboBox::hide()
{
	ShowWindow(hComboBox,SW_HIDE);
}


void MyComboBox::show()
{
	ShowWindow(hComboBox,SW_SHOW);
}
void MyComboBox::setText(LPTSTR text)
{
	SetWindowText(hComboBox,text);
}
void MyComboBox::setCurSel(int index)
{
	SendMessage(hComboBox,CB_SETCURSEL,index,0);
}
LPTSTR MyComboBox::getItem(int index)
{
	TCHAR buffer[100];
	SendMessage(hComboBox,CB_GETLBTEXT,index,(LPARAM)buffer);
	return buffer;
}
void MyComboBox::add(LPTSTR szText)
{
	int index = SendMessage(hComboBox,CB_GETCOUNT,0,0);
	COMBOBOXEXITEM cbei;
	cbei.mask = CBEIF_TEXT;
	cbei.cchTextMax = 50;
	cbei.pszText = szText;
	cbei.iItem = index;
	SendMessage(hComboBox,CBEM_INSERTITEM,0,(LPARAM)&cbei);
}
int MyComboBox::count()
{
	return SendMessage(hComboBox,CB_GETCOUNT,0,0);
}
LPTSTR MyComboBox::getText()
{
	TCHAR str[100] ;
	COMBOBOXEXITEM cbei;

	cbei.mask = CBEIF_TEXT;
	cbei.cchTextMax = 100;
	cbei.pszText = str;
	int resu = SendMessage(hComboBox,CB_GETCURSEL,0,0);
	cbei.iItem = resu;

	SendMessage(hComboBox,CBEM_GETITEM,0,(LPARAM)&cbei);
	wcscpy(str , cbei.pszText);
	return str;
}
void MyComboBox::move(int x, int y, int cx, int cy)
{
	MoveWindow(hComboBox,x, y, cx, cy,TRUE);
}